<template>
  <li
    class="song-item"
    @click="
      $emit('update:music', { item, index });
      $emit('update:playlist');
    "
  >
    <div class="paixv">{{ (index + 1) | capitalize(index) }}</div>
    <div class="info">
      <h5>{{ item.name }}</h5>
      <p>
        <i class="SQ"></i>
        <span v-for="(artist, index) in item.ar" :key="index">
          <template v-if="index"> / </template>{{ artist.name }}
        </span>
      </p>
    </div>
    <div class="icon">
      <span
        class="playing"
        :class="{ paused: paused }"
        v-if="currentMusic && currentMusic.id === item.id"
      >
        <i></i>
        <i></i>
        <i></i>
      </span>
      <span v-else class="iconA"><img src="../assets/playicon.svg" /></span>
    </div>
  </li>
</template>

<script>
export default {
  props: ["item", "index", "currentMusic", "paused"],
  // created() {
  //   console.log('$root',this.$root);
  //   console.log('$parent',this.$parent);
  // },
  filters: {
    capitalize: function (value) {
      if (value < 10) {
        return "0" + value;
      }
      return value;
    },
  },
};
</script>

<style scoped lang="less">
li.song-item {
  width: 320px;
  height: 60px;
  display: flex;
  // line-height: 60px;
  position: relative;

  .paixv {
    // width: 30px;
    height: 60px;
    line-height: 60px;
    display: inline-block;
    font-size: 17px;
    color: #999999;
  }
  .info {
    flex: 1;
    margin-top: 10px;
    text-overflow: -o-ellipsis-lastline;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    h5 {
      color: #333333;
      font-size: 17px;
      margin-left: 10px;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      line-clamp: 1;
      -webkit-box-orient: vertical;
      // text-overflow: ellipsis;
      // overflow: hidden;
      // white-space: nowrap;
    }
    p {
      height: 20px;
      line-height: 20px;
      margin-left: 10px;
      .SQ {
        display: inline-block;
        background: url("../assets/icon.png") no-repeat 0 0;
        width: 24px;
        height: 16px;
        transform: scale(0.5);
        position: relative;
        top: 5px;
      }
      span {
        font-size: 12px;
        color: #888888;
        margin: 0;
      }
    }
  }
  .icon {
    width: 30px;
    height: 30px;
    .iconA {
      position: absolute;
      right: -26px;
      top: 10px;
      img {
        width: 25px;
        height: 25px;
      }
    }
    .playing {
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      i {
        width: 4px;
        height: 30px;
        background: red;
        // display: inline-block;
        transform-origin: center bottom;
        border-radius: 5px 5px 0 0;

        animation: playing 0.6s linear -0.2s infinite alternate-reverse;

        &:first-of-type {
          animation-delay: 0s;
        }
        &:last-of-type {
          animation-delay: -0.4s;
        }
      }
      &.paused {
        i {
          animation-play-state: paused;
        }
      }
    }
  }
}

@keyframes playing {
  from {
    // height: 50px;
    transform: scaleY(1);
  }
  to {
    // height: 10px;
    transform: scaleY(0.2);
  }
}
</style>